//
//  WYTAlertView.m
//  Diary
//
//  Created by 王艺拓 on 15/11/10.
//  Copyright © 2015年 王艺拓. All rights reserved.
//

#import "WYTAlertView.h"

@implementation WYTAlertView

- (instancetype)init{
    self = [super init];
    if (self) {
        
        [self setUps];
        [self setUpScene];
        self.alpha = 0;
        
        [self performSelector:@selector(delayAfterAnimation) withObject:self afterDelay:0.3];
    }
    return self;
}

- (void)setUps{
    self.frame = CGRectMake(kScreenWidth / 3, kScreenHeight / 5 * 2, kScreenWidth / 3 * 2 * 0.5, kScreenWidth / 3 * 2 / 4 * 3 * 0.5);
    [self setUpScene];
    self.alpha = 0.8;
}

- (void)setUpScene{
    self.baseImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame))];
    self.baseImageView.image = [UIImage imageNamed:@"shareFailed"];
    [self addSubview:self.baseImageView];
    
    self.AlertLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.baseImageView.frame) / 4 * 2.7, CGRectGetWidth(self.baseImageView.frame), CGRectGetHeight(self.baseImageView.frame) / 4)];
    self.AlertLabel.text = @"网络连接失败";
    self.AlertLabel.textColor = [UIColor whiteColor];
    self.AlertLabel.textAlignment = NSTextAlignmentCenter;
    NSInteger alertLabelFontSize = 15;
    self.AlertLabel.font = [UIFont boldSystemFontOfSize:alertLabelFontSize];
    self.AlertLabel.textColor = [UIColor colorWithRed:64/255.0 green:64/255.0 blue:64/255.0 alpha:1.0f];
    [self.baseImageView addSubview:self.AlertLabel];
    
    self.baseImageView.layer.masksToBounds = YES;
    self.baseImageView.layer.cornerRadius = 5;
}

+ (WYTAlertView *)setUpAlertViewWithSucceed:(BOOL)succeedOrFailed alertLabelText:(NSString *)alertLabelText;{
    
    WYTAlertView *alertView = [[WYTAlertView alloc]init];
    if (succeedOrFailed == NO) {
        alertView.baseImageView.image = [UIImage imageNamed:@"shareFailed"];
    }else{
        alertView.baseImageView.image = [UIImage imageNamed:@"shareSucceed"];
    }
    alertView.AlertLabel.text = alertLabelText;
#warning alertView的字体的改变
    alertView.AlertLabel.font = [UIFont systemFontOfSize:13];
    return alertView;
}

+ (WYTAlertView *)setUpAlertViewWithClockSuggestionWithAlertLabelText:(NSString *)alertLabelText{
    WYTAlertView *alertView = [[WYTAlertView alloc]init];
    alertView.baseImageView.image = [UIImage imageNamed:@"clockSuggestion"];
    alertView.AlertLabel.text = alertLabelText;
    return alertView;
}

+ (WYTAlertView *)setUpAlertViewWithTextFiledSuggestionWithAlertLabelText:(NSString *)alertLabelText{
    WYTAlertView *alertView = [[WYTAlertView alloc]init];
    alertView.baseImageView.image = [UIImage imageNamed:@"swipeToJumpTextField"];
    alertView.AlertLabel.text = alertLabelText;
    return alertView;
}

+ (WYTAlertView *)setUpTextViewAlertView{
    WYTAlertView *alertView = [[WYTAlertView alloc]init];
    alertView.baseImageView = nil;
    alertView.AlertLabel.text = @"卡片快装不下了";
    return alertView;
}

- (void)delayAfterAnimation{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
    }];
    [self performSelector:@selector(disappear) withObject:self afterDelay:0.5];
}

- (void)disappear{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    }];
    [self performSelector:@selector(remove) withObject:self afterDelay:0.4];
}

- (void)remove{
    [self removeFromSuperview];
}


@end
